{extend name="ace/layout/default" /}

{block name="title"}网站设置{/block}

{block name="content"}

{include file="ace/layout:ueditor" /}

<h3 class="header smaller lighter blue">
    网站设置
    <small>
        <i class="icon-double-angle-right"></i>
        可以在此增改系统的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除。
    </small>
</h3>

<div class="row">
    <div class="col-sm-1"></div>
    <div class="col-sm-10">
        <div class="tabbable">
            <?php $active_key = input('active_key', 0);?>
            <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab4">
                {if !empty($config_group_list)}
                    {foreach $config_group_list as $key => $group_list}
                        <li class="{if $active_key == $key}active{/if} margin-bottom-1-rem" onclick="changeUrl(this)">
                            <a active-key="{$key}" href="#config_group_{$key}" data-toggle="tab">{$group_list}</a>
                        </li>
                    {/foreach}
                {/if}
            </ul>

            <form id="basic-form" class="edit-form form-horizontal" method="POST" action="{:url('update')}" return-url="{:url('index')}"
                  onsubmit="saveOperation(this);return false;">
                <div class="tab-content">
                    {if !empty($config_group_list)}
                        {foreach $config_group_list as $key => $group_list}
                            <div id="config_group_{$key}" class="tab-pane {if $active_key == $key}active in{/if}">
                                <div class="widget-body no-padding">
                                    <table class="table table-striped">
                                        <thead>
                                        <tr>
                                            <th width="15%">变量标题</th>
                                            <th width="70%">变量值</th>
                                            <th width="15%">变量名</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        {if !empty($configs_list[$key])}
                                            {foreach $configs_list[$key] as $config}
                                                <tr>
                                                    <td>{$config.config_title}</td>
                                                    <td>
                                                        <div class="row">
                                                            <div class="col-sm-8 col-xs-12">
                                                                {switch config.config_type}
                                                                {case 3}<!--数组-->
                                                                <textarea class="form-control height-20rem" name="{$config.config_name}">{$config.config_value}</textarea>
                                                                {/case}
                                                                {case 4}<!--枚举-->
                                                                <select class="form-control" name="{$config.config_name}">
                                                                    {if !empty($config.config_extra)}
                                                                        {foreach $config.config_extra as $key => $config_extra}
                                                                            <option value="{$key}" {if $key == $config.config_value}selected{/if} > {$config_extra} </option>
                                                                        {/foreach}
                                                                    {/if}
                                                                </select>
                                                                {/case}
                                                                {case 6}<!--富文本-->
                                                                <script class="container" id="container-{$config.config_name}" name="{$config.config_name}" type="text/plain">{:htmlspecialchars_decode($config.config_value)}</script>
                                                                <script>
                                                                    $(function () {
                                                                        uediotr('container-{$config.config_name}');
                                                                    });
                                                                </script>
                                                                {/case}
                                                                {default /}
                                                                <input class="form-control" type="text" name="{$config.config_name}" data-rule="" data-tip="{$config.config_remarks}" value="{$config.config_value}"/>
                                                                {/switch}
                                                            </div>
                                                            <div class="col-sm-4"></div>
                                                        </div>
                                                    </td>
                                                    <td>{$config.config_name}</td>
                                                </tr>
                                            {/foreach}
                                        {/if}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        {/foreach}
                    {/if}
                </div>
            </form>
            <div class="space-4"></div>
            <div class="center">
                <button type="submit" class="btn btn-success btn-embossed" onclick="$('form#basic-form').submit()"> 全部更新 </button>
            </div>
        </div>
    </div><!-- /span -->
    <div class="col-sm-1"></div>
</div><!-- /row -->
{/block}

{block name="script"}
<script>
    function changeUrl(_this) {
        var stateObject = {id: $(_this).find('a').html()};
        var title = document.title + $(_this).find('a').html();
        var newUrl = thisUrl() + '?active_key=' + $(_this).find('a').attr('active-key');
        // 更改URL地址，但是不做跳转
        history.pushState(stateObject, title, newUrl);
    }
</script>
{/block}